package com.mvc4g.example.client.customer.views;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LazyPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Controller;
import com.mvc4g.client.ViewInterface;
import com.mvc4g.example.client.Constants;
import com.mvc4g.example.client.customer.CustomerBean;

public abstract class AbstractCustomerView extends LazyPanel implements
		ViewInterface, Constants {

	protected Controller controller = null;

	protected Grid grid = null;

	@Override
	protected Widget createWidget() {

		grid = new Grid(2, 2);
		grid.setWidget(0, 0, new Label("Last Name:"));
		grid.setWidget(1, 0, new Label("First Name:"));

		Button button = new Button(getButtonText());
		button.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				buttonAction();
			}

		});

		finishCreation();

		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.setPixelSize(300, 100);
		mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		mainPanel.add(grid);
		mainPanel.add(button);

		return mainPanel;
	}

	@Override
	public void setController(Controller controller) {
		this.controller = controller;
	}

	abstract public void init(CustomerBean customer);

	abstract protected String getButtonText();

	abstract protected void buttonAction();

	abstract protected void finishCreation();

}
